using MediatR;
using SumerCoreDevOps.Application.GitTriggers.Queries;
using SumerCoreDevOps.Domain.Entities;
using SumerCoreDevOps.Infrastructure.GitTrigger;

namespace SumerCoreDevOps.Application.GitTriggers.Handlers;

/// <summary>
/// 根据 ID 获取触发规则查询处理器
/// </summary>
public class GetGitTriggerRuleByIdQueryHandler : IRequestHandler<GetGitTriggerRuleByIdQuery, GitTriggerRule?>
{
    private readonly GitTriggerRuleManager _ruleManager;

    public GetGitTriggerRuleByIdQueryHandler(GitTriggerRuleManager ruleManager)
    {
        _ruleManager = ruleManager;
    }

    public async Task<GitTriggerRule?> Handle(GetGitTriggerRuleByIdQuery request, CancellationToken cancellationToken)
    {
        return await _ruleManager.GetRuleByIdAsync(request.Id);
    }
}
